﻿@model Category
@{
	PageTitle.AddViewTitle("Каталог", Url.Action("Index"));

	if (ViewData["Parent"] != null)
	{
		List<Category> categoriesForTitle = new List<Category>();
		Category c = ViewData["Parent"].To<Category>();
		while (c != null)
		{
			categoriesForTitle.Insert(0, c);
			c = c.Parent;
		}

		foreach (Category cc in categoriesForTitle)
		{
			PageTitle.AddViewTitle(cc.Title, Url.Action("Index", new { parentId = cc.Id }));
		}
	}
	
	if (Model == null)
	{
		PageTitle.AddViewTitle("Добавление категории");
	}
	else
	{
		PageTitle.AddViewTitle(Model.Title, Url.Action("Index", new { parentId = Model.Id }));
		PageTitle.AddViewTitle("Изменение");
	}
}

@section head {
	@Html.Partial("Mce", new MceModel(false, null))
}

@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" })) {
	@Html.Hidden("returnUrl")
	@Html.ValidationSummary()
	<p><span class="red">*</span> - обязательные поля</p>
	<fieldset class="form-horizontal">
		<div class="required">
			@Html.LabelFor(m => m.Title)
			@Html.TextBoxFor(m => m.Title)
		</div>
		<div>
			@Html.LabelFor(m => m.Parent)
			@Html.DropDownListFor(m => m.Parent.Id, (IEnumerable<SelectListItem>)ViewBag.Parents)
		</div>
		<div class="vertical">
			@Html.LabelFor(m => m.Text)
			@Html.TextAreaFor(m => m.Text, new { @class = "tinymce", style = "height:400px" })
		</div>
		<div>
			<label>@Html.DisplayNameFor(m => m.ShowTiles)</label>
			<div>
				<label for="ShowTilesFalse" class="checkbox-inline">@Html.RadioButtonFor(m => m.ShowTiles, false, new { id = "ShowTilesFalse" }) Списком</label>
				<label for="ShowTilesTrue" class="checkbox-inline">@Html.RadioButtonFor(m => m.ShowTiles, true, new { id = "ShowTilesTrue" }) Плашками</label>
			</div>
		</div>
		<div>
			@Html.LabelFor(m => m.Picture)
			@Html.ImageUpload("Picture", "ImageType")
		</div>
	</fieldset>
	
	<div class="form-buttons">
		<input type="submit" value="@(Model == null ? "Добавить" : "Изменить")" />&nbsp;
		<a href="@ViewData["returnUrl"]">Отменить</a>
	</div>
}